<script src="/static/js/jquery-2.1.1.js"></script>
<script src="/static/bootstrap/js/bootstrap.js"></script>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
<link href="/static/layui/css/layui.css" rel="stylesheet"/>
<script src="/static/layui/layui.js"></script>

<style>
    .config_img{height:45px;margin-top:15px;}
    .layui-form-label{padding:9px 5px;}
    .layui-input-block{margin-left:85px;}
    .layui-form-item .layui-form-checkbox[lay-skin=primary]{
        margin-top:10px!important;
    }
</style>


<div class="modal-body">

    <div class="new-content">
        <form name="add_form" class="form-horizontal layui-form">

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">名称</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="title" placeholder="名称" value="{$detail.title}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">发布部门</label>
                <div class="layui-input-block ml-110">
                    <select name="department" lay-verify="department" lay-filter="department" >
                        <option value="0">请选择</option>
                        {volist name="departmentList" id="vo"}
                            <option value="{$vo.id}" {if condition="$detail['department'] eq $vo['id']"} selected {/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">生效日期</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control time" name="startTime" placeholder="生效日期" value="{$detail.startTime}">
                </div>
                <div style="color: red">为空表示长期有效</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">失效日期</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control time" name="endTime" placeholder="生效日期" value="{$detail.endTime}">
                </div>
                <div style="color: red">为空表示长期有效</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">企业规模</label>
                <div class="layui-input-block ml-110">
                    <select name="scale" lay-verify="scale" lay-filter="scale" >
                        <option value="0">请选择</option>
                        {volist name="scaleList" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['scale'] eq $vo['id']"} selected {/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">行业</label>
                <div class="layui-input-block ml-110">
                    <select name="industry" lay-verify="industry" lay-filter="industry" >
                        <option value="0">请选择</option>
                        {volist name="industryList" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['industry'] eq $vo['id']"} selected {/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">股室名称</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="thigh" placeholder="股室名称" value="{$detail.thigh}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label wd-140">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" class="form-control" name="contact" placeholder="联系电话" value="{$detail.contact}">
                </div>
            </div>


            <div class="layui-form-item js_photos">
                <label class=" layui-form-label"> *文件</label>
                <div class="layui-input-block logo">
                    <div class="input-group ">
                        <input type="file" name="" class="do_upload" data-val="path"  style="display: none">
                        <input type="text" class="form-control path" name="path" disabled="" value="{$detail.path}" >
                        <input type="hidden" class="form-control path" name="path" value="{$detail.path}" >
                        <span class="group-span-filestyle input-group-btn" tabindex="0">
                            <label class="btn btn-default id_photos" data-original-title="" title="">
                                <span class="glyphicon glyphicon-folder-open"></span>
                                上传
                            </label>
                        </span>
                        </span>
                    </div>
                    {if condition="$detail.path neq ''"}
                    <a target="_blank" href="{$detail.path}">查看文件</a>
                    {/if}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">推送企业</label>
                <div id="business" class="demo-transfer"></div>
            </div>
            <input type="hidden" name="business" value="{$detail.business}">

            <input type="hidden" name="id" value="{$detail.id}">
        </form>
    </div>

</div>

<script>
    layui.use(['form','laydate','transfer'], function() {
        var form = layui.form
            , layer = layui.layer;
        var layedit = layui.layedit;
        var  tree = layui.tree;
        var util = layui.util;
        var laydate = layui.laydate;
        var transfer = layui.transfer;

        //同时绑定多个
        lay('.time').each(function(){
            laydate.render({
                elem: this
                ,trigger: 'click'
                ,type: 'date'
                ,theme: 'molv'
            });
        });


        //责任单位
        var account= {$account};
        // //责任单位
        transfer.render({
            elem: '#business'
            ,id:'business'
            ,data: account
            ,title: ['全选', '全选']
            ,showSearch: true
            ,height:200
            ,value:{$account_k}
            ,onchange: function(data, index){
                //获取穿梭框右边数据
                var business = transfer.getData('business');
                business = eachvalue(business);
                $("input[name='business']").val(business);
            }
        }),

        layui.form.render('select');
        form.render();
    });



    function eachvalue(data){
        var newvalue = '';
        $.each(data,function (index,value) {
            newvalue+=value.title+";";
        });
        return newvalue;
    };


    $(".id_photos").click(function () {
        $(this).parent().parent().find(".do_upload").click();
    });

    $('.js_photos').on('change','.do_upload',function(){
        var content = $(this).attr("data-val");
        var formData = new FormData();
        var name = $($(this)).val();
        var files = $($(this))[0].files[0];
        formData.append("file", files);
        formData.append("name", name);
        //另外加的参数
        formData.append("act", "PostImg");
        // var index = layer.msg('正在提交中....');

        $.ajax({
            url: "{:URL('common/upload/ad_upload')}",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                $("."+content).val(res.path);
                $("."+content).find("img").attr("src",res.path);
            }
            ,error:function (res) {
                alert('错误');
            }
        });
    })
</script>